package com.mg.controller;

import com.github.pagehelper.PageInfo;
import com.mg.common.Constants;
import com.mg.dto.PresentRecordDto;
import com.mg.dto.SimpleResult;
import com.mg.model.PresentRecord;
import com.mg.model.User;
import com.mg.service.PresentRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by mg1213 on 2018/3/18.
 */
@Controller
@RequestMapping("/presentRecord")
public class PresentRecordController {
    @Autowired
    private PresentRecordService presentRecordService;

    @RequestMapping(value = "/user/selectPageInfo")
    @ResponseBody
    public PageInfo<PresentRecordDto> selectUserPageInfo(PresentRecordDto dto, int limit, int start) {
        return presentRecordService.selectPageInfo(dto, start, limit);
    }
    @RequestMapping(value = "/admin/selectPageInfo")
    @ResponseBody
    public PageInfo<PresentRecordDto> selectPageInfo(PresentRecordDto dto, int limit, int start) {
        return presentRecordService.selectPageInfo(dto, start, limit);
    }
    @RequestMapping(value = "/admin/insertPresentRecord")
    @ResponseBody
    public SimpleResult insertPresentRecord(PresentRecord record) {
        return presentRecordService.insertPresentRecord(record);
    }
    @RequestMapping(value = "/user/savePresentRecord")
    @ResponseBody
    public SimpleResult savePresentRecord(PresentRecord record, HttpServletRequest request) {
        User  user= (User) request.getSession().getAttribute(Constants.USER_INFO);
        record.setUserId(user.getId());
        return presentRecordService.insertPresentRecord(record);
    }
    @RequestMapping(value = "/admin/updatePresentRecord")
    @ResponseBody
    public SimpleResult updatePresentRecord(PresentRecord record) {
        return presentRecordService.updatePresentRecord(record);
    }
    @RequestMapping(value = "/admin/deletePresentRecord")
    @ResponseBody
    public SimpleResult deletePresentRecord(String ids) {
        return presentRecordService.deletePresentRecord(ids);
    }

}
